package com.gthncz;

import java.util.Scanner;

public class Demo3 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String frame = sc.nextLine();
            String brick = sc.nextLine();

            if (brick.length() > frame.length()) {
                System.out.print(-1);
                continue;
            }

            // 1. 找 frame 中最小, brick 最大
            int minFrame = Integer.MAX_VALUE;
            int min = 0, k=0;
            for (char c: frame.toCharArray()) {
                if (c-'0' < minFrame) {
                    minFrame = c - '0';
                    min = k;
                }
                ++k;
            }

            int maxBrick = Integer.MIN_VALUE;
            int max = 0; k=0;
            for (char c: brick.toCharArray()) {
                if (c-'0' > maxBrick) {
                    maxBrick = c - '0';
                    max = k;
                }
                ++k;
            }

            // 分情况累加
            
        }

    }

}
